package junior.贪心算法;

public class 快排 {
    static int[] array = {4,6,3,2,5,1};
    public static void main(String[] args) {

        quickSort(array,0, array.length-1);

        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+"\t");
        }
        System.out.println();
    }
    public static int[] quickSort(int[] array,int start, int end){
        int pivot = array[start];
        int i = start;
        int j = end;
        while (i<j) {
            while (i<j && array[j] > pivot)
                j--;
            while (i<j && array[i] < pivot)
                i++;
            if (i<j && array[i]==array[j]) {
                i++;
            } else {
                int temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
        }
        if (i-1 > start)
            array=quickSort(array,start,i-1);
        if (j+1 < end)
            array=quickSort(array,j+1,end);
        return array;
    }
}
